package com.dcjt.firehotcarpad.utils;

import android.content.Context;
import android.graphics.Color;

import com.bigkoo.pickerview.TimePickerView;
import com.dcjt.firehotcarpad.R;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by cj on 2017/11/6.
 * desc:滚轮选择器
 */

public class PickUtil {

    public PickUtil(){ throw new IllegalArgumentException("can't be init");}

    public static void selectDate(Context context, OnSelectTime selectTime){
        selectDate(context,new Date(),selectTime);
    }


    public static void selectDate(Context context, Date dateSet, OnSelectTime selectTime){
        //控制时间范围(如果不设置范围，则使用默认时间1900-2100年，此段代码可注释)
        //因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,
        // 月份的范围也要是从0-11

        Calendar startDate = Calendar.getInstance();
        Calendar endDate = Calendar.getInstance();

//        startDate.setTime(dateSet);
//        endDate.set(2022, 12, 31);
//
        endDate.setTime(dateSet);
        startDate.set(2020, 1, 1);


        TimePickerView pvTime = new TimePickerView.Builder(context, (date, v) -> {//选中事件回调
            // 这里回调过来的v,就是show()方法里面所添加的 View 参数，如果show的时候没有添加参数，v则为null

            if (selectTime != null) selectTime.selectTime(date);
        })
                .setLabel(" 年", "月", "日", "时", "分", "秒")
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLineSpacingMultiplier(8)
                .isCenterLabel(true)
                .setDividerColor(Color.DKGRAY)
                .setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setContentSize(16)
                .setSubCalSize(16)
                .setTitleSize(16)
                .setDate(endDate)
                .setSubmitColor(context.getResources().getColor(R.color.titleBg))
                .setCancelColor(Color.parseColor("#CECECE"))
                .setRangDate(startDate, endDate)
                .setTextColorCenter(Color.parseColor("#3c3c3c"))
                .setTextColorOut(Color.parseColor("#9b9b9b"))
                .setTitleBgColor(Color.parseColor("#ffffff"))
                .setDividerColor(Color.parseColor("#DCDCDC"))
//                .setBackgroundId(0x66000000) //设置外部遮罩颜色
                .setDecorView(null)
                .build();

        pvTime.show();
    }

    public interface OnSelectTime{
        void selectTime(Date date);
    }
}
